import { ConfigService, ConfigModule } from '@nestjs/config'
import { Module } from '@nestjs/common'
import { UserController } from './user.controller'
import { UserService } from './user.service'
import { User, UserSchema } from '../model/UserSchema.Schema'
import { SubBar, subBarSchema } from '../model/subBar.schema'
import { Collect, collectSchema } from '../model/collect.schema'
import { Comment, commentSchema } from '../model/comment.schema'
import { MongooseModule } from '@nestjs/mongoose'
import { JwtModule } from '@nestjs/jwt'
import { JwtStrategy } from '../strategy/jwt.strategy'
import { Friend, friendSchema } from '../model/friend.schema'
import { Inform, informSchema } from '../model/inform.schema'
import { friendVerifySchema, FriendVerify } from '../model/friendVerify.schema'
@Module({
  imports: [
    MongooseModule.forFeature([
      { schema: UserSchema, name: User.name },
      { name: SubBar.name, schema: subBarSchema },
      { name: Collect.name, schema: collectSchema },
      { name: Friend.name, schema: friendSchema },
      { name: Inform.name, schema: informSchema },
      { name: FriendVerify.name, schema: friendVerifySchema },
    ]),
    //配置token
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory(config: ConfigService) {
        return {
          secret: config.get('TOKEN_SECRET'),
          signOptions: { expiresIn: '6h' },
        }
      },
    }),
  ],
  controllers: [UserController],
  providers: [UserService, JwtStrategy],
  exports: [
    UserService,
    MongooseModule.forFeature([
      { schema: UserSchema, name: User.name },
      { name: Comment.name, schema: commentSchema },
      { name: Friend.name, schema: friendSchema },
      { name: Inform.name, schema: informSchema },
      { name: FriendVerify.name, schema: friendVerifySchema },
    ]),
  ],
})
export class UserModule {}
